package org.jivesoftware.smack.packet;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.TimeZone;
import java.util.concurrent.CopyOnWriteArrayList;
import org.jivesoftware.smack.util.StringUtils;

public abstract class Packet
{
  protected static final String DEFAULT_LANGUAGE = Locale.getDefault().getLanguage().toLowerCase();
  private static String DEFAULT_XML_NS = null;
  public static final String ID_NOT_AVAILABLE = "ID_NOT_AVAILABLE";
  public static final DateFormat XEP_0082_UTC_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
  private static long id;
  private static String prefix;
  private XMPPError error;
  private String from;
  private final List<PacketExtension> packetExtensions;
  private String packetID;
  private final Map<String, Object> properties;
  private String to;
  private String xmlns = DEFAULT_XML_NS;

  static
  {
    XEP_0082_UTC_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC"));
    prefix = StringUtils.randomString(5) + "-";
    id = 0L;
  }

  public Packet()
  {
    this.packetID = null;
    this.to = null;
    this.from = null;
    this.packetExtensions = new CopyOnWriteArrayList();
    this.properties = new HashMap();
    this.error = null;
  }

  public static String getDefaultLanguage()
  {
    return DEFAULT_LANGUAGE;
  }

  /**
   * @deprecated
   */
  public static String nextID()
  {
    monitorenter;
    try
    {
      StringBuilder localStringBuilder = new StringBuilder(String.valueOf(prefix));
      long l = id;
      id = 1L + l;
      String str = Long.toString(l);
      monitorexit;
      return str;
    }
    finally
    {
      localObject = finally;
      monitorexit;
      throw localObject;
    }
  }

  public static void setDefaultXmlns(String paramString)
  {
    DEFAULT_XML_NS = paramString;
  }

  public void addExtension(PacketExtension paramPacketExtension)
  {
    this.packetExtensions.add(paramPacketExtension);
  }

  /**
   * @deprecated
   */
  public void deleteProperty(String paramString)
  {
    monitorenter;
    try
    {
      Map localMap = this.properties;
      if (localMap == null)
      {
        monitorexit;
        return;
      }
    }
    finally
    {
      monitorexit;
    }
  }

  public boolean equals(Object paramObject)
  {
    int i;
    if (this == paramObject)
      i = 1;
    while (true)
    {
      Packet localPacket;
      while (true)
      {
        while (true)
        {
          return i;
          if ((paramObject != null) && (super.getClass() == paramObject.getClass()))
            break;
          i = 0;
        }
        localPacket = (Packet)paramObject;
        if (this.error != null)
          if (this.error.equals(localPacket.error))
            break label67;
        do
          while (true)
            i = 0;
        while (localPacket.error != null);
        if (this.from != null)
          label67: if (this.from.equals(localPacket.from))
            break label100;
        do
          while (true)
            i = 0;
        while (localPacket.from != null);
        label100: if (this.packetExtensions.equals(localPacket.packetExtensions))
          break;
        i = 0;
      }
      if (this.packetID != null)
        if (this.packetID.equals(localPacket.packetID))
          break label154;
      do
        while (true)
          i = 0;
      while (localPacket.packetID != null);
      if (this.properties != null)
        label154: if (this.properties.equals(localPacket.properties))
          break label189;
      do
        while (true)
          i = 0;
      while (localPacket.properties != null);
      if (this.to != null)
        label189: if (this.to.equals(localPacket.to))
          break label222;
      do
        while (true)
          i = 0;
      while (localPacket.to != null);
      if (this.xmlns != null)
        label222: if (this.xmlns.equals(localPacket.xmlns))
          break label255;
      do
        while (true)
          i = 0;
      while (localPacket.xmlns != null);
      label255: i = 1;
    }
  }

  public XMPPError getError()
  {
    return this.error;
  }

  public PacketExtension getExtension(String paramString)
  {
    return getExtension(null, paramString);
  }

  public PacketExtension getExtension(String paramString1, String paramString2)
  {
    Object localObject;
    if (paramString2 == null)
      localObject = null;
    while (true)
    {
      PacketExtension localPacketExtension;
      return localObject;
      Iterator localIterator = this.packetExtensions.iterator();
      do
      {
        while (!(localIterator.hasNext()))
          localObject = null;
        localPacketExtension = (PacketExtension)localIterator.next();
      }
      while (((paramString1 != null) && (!(paramString1.equals(localPacketExtension.getElementName())))) || (!(paramString2.equals(localPacketExtension.getNamespace()))));
      localObject = localPacketExtension;
    }
  }

  /**
   * @deprecated
   */
  public Collection<PacketExtension> getExtensions()
  {
    List localList1;
    Object localObject2;
    monitorenter;
    try
    {
      if (this.packetExtensions == null)
      {
        List localList2 = Collections.emptyList();
        localObject2 = localList2;
        monitorexit;
        return localObject2;
      }
      localList1 = Collections.unmodifiableList(new ArrayList(this.packetExtensions));
    }
    finally
    {
      monitorexit;
    }
  }

  /**
   * @deprecated
   */
  // ERROR //
  protected String getExtensionsXML()
  {
    // Byte code:
    //   0: aload_0
    //   1: monitorenter
    //   2: new 73	java/lang/StringBuilder
    //   5: dup
    //   6: invokespecial 202	java/lang/StringBuilder:<init>	()V
    //   9: astore_1
    //   10: aload_0
    //   11: invokevirtual 204	org/jivesoftware/smack/packet/Packet:getExtensions	()Ljava/util/Collection;
    //   14: invokeinterface 207 1 0
    //   19: astore_3
    //   20: aload_3
    //   21: invokeinterface 169 1 0
    //   26: ifne +68 -> 94
    //   29: aload_0
    //   30: getfield 117	org/jivesoftware/smack/packet/Packet:properties	Ljava/util/Map;
    //   33: ifnull +50 -> 83
    //   36: aload_0
    //   37: getfield 117	org/jivesoftware/smack/packet/Packet:properties	Ljava/util/Map;
    //   40: invokeinterface 210 1 0
    //   45: ifne +38 -> 83
    //   48: aload_1
    //   49: ldc 212
    //   51: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   54: pop
    //   55: aload_0
    //   56: invokevirtual 215	org/jivesoftware/smack/packet/Packet:getPropertyNames	()Ljava/util/Collection;
    //   59: invokeinterface 207 1 0
    //   64: astore 7
    //   66: aload 7
    //   68: invokeinterface 169 1 0
    //   73: ifne +48 -> 121
    //   76: aload_1
    //   77: ldc 217
    //   79: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   82: pop
    //   83: aload_1
    //   84: invokevirtual 93	java/lang/StringBuilder:toString	()Ljava/lang/String;
    //   87: astore 5
    //   89: aload_0
    //   90: monitorexit
    //   91: aload 5
    //   93: areturn
    //   94: aload_1
    //   95: aload_3
    //   96: invokeinterface 173 1 0
    //   101: checkcast 175	org/jivesoftware/smack/packet/PacketExtension
    //   104: invokeinterface 220 1 0
    //   109: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   112: pop
    //   113: goto -93 -> 20
    //   116: astore_2
    //   117: aload_0
    //   118: monitorexit
    //   119: aload_2
    //   120: athrow
    //   121: aload 7
    //   123: invokeinterface 173 1 0
    //   128: checkcast 40	java/lang/String
    //   131: astore 8
    //   133: aload_0
    //   134: aload 8
    //   136: invokevirtual 224	org/jivesoftware/smack/packet/Packet:getProperty	(Ljava/lang/String;)Ljava/lang/Object;
    //   139: astore 9
    //   141: aload_1
    //   142: ldc 226
    //   144: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   147: pop
    //   148: aload_1
    //   149: ldc 228
    //   151: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   154: aload 8
    //   156: invokestatic 232	org/jivesoftware/smack/util/StringUtils:escapeForXML	(Ljava/lang/String;)Ljava/lang/String;
    //   159: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   162: ldc 234
    //   164: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   167: pop
    //   168: aload_1
    //   169: ldc 236
    //   171: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   174: pop
    //   175: aload 9
    //   177: instanceof 238
    //   180: ifeq +30 -> 210
    //   183: aload_1
    //   184: ldc 240
    //   186: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   189: aload 9
    //   191: invokevirtual 243	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   194: ldc 245
    //   196: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   199: pop
    //   200: aload_1
    //   201: ldc 247
    //   203: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   206: pop
    //   207: goto -141 -> 66
    //   210: aload 9
    //   212: instanceof 123
    //   215: ifeq +23 -> 238
    //   218: aload_1
    //   219: ldc 249
    //   221: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   224: aload 9
    //   226: invokevirtual 243	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   229: ldc 245
    //   231: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   234: pop
    //   235: goto -35 -> 200
    //   238: aload 9
    //   240: instanceof 251
    //   243: ifeq +23 -> 266
    //   246: aload_1
    //   247: ldc 253
    //   249: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   252: aload 9
    //   254: invokevirtual 243	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   257: ldc 245
    //   259: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   262: pop
    //   263: goto -63 -> 200
    //   266: aload 9
    //   268: instanceof 255
    //   271: ifeq +24 -> 295
    //   274: aload_1
    //   275: ldc_w 257
    //   278: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   281: aload 9
    //   283: invokevirtual 243	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   286: ldc 245
    //   288: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   291: pop
    //   292: goto -92 -> 200
    //   295: aload 9
    //   297: instanceof 259
    //   300: ifeq +24 -> 324
    //   303: aload_1
    //   304: ldc_w 261
    //   307: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   310: aload 9
    //   312: invokevirtual 243	java/lang/StringBuilder:append	(Ljava/lang/Object;)Ljava/lang/StringBuilder;
    //   315: ldc 245
    //   317: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   320: pop
    //   321: goto -121 -> 200
    //   324: aload 9
    //   326: instanceof 40
    //   329: ifeq +34 -> 363
    //   332: aload_1
    //   333: ldc_w 263
    //   336: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   339: pop
    //   340: aload_1
    //   341: aload 9
    //   343: checkcast 40	java/lang/String
    //   346: invokestatic 232	org/jivesoftware/smack/util/StringUtils:escapeForXML	(Ljava/lang/String;)Ljava/lang/String;
    //   349: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   352: pop
    //   353: aload_1
    //   354: ldc 245
    //   356: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   359: pop
    //   360: goto -160 -> 200
    //   363: aconst_null
    //   364: astore 13
    //   366: aconst_null
    //   367: astore 14
    //   369: new 265	java/io/ByteArrayOutputStream
    //   372: dup
    //   373: invokespecial 266	java/io/ByteArrayOutputStream:<init>	()V
    //   376: astore 15
    //   378: new 268	java/io/ObjectOutputStream
    //   381: dup
    //   382: aload 15
    //   384: invokespecial 271	java/io/ObjectOutputStream:<init>	(Ljava/io/OutputStream;)V
    //   387: astore 16
    //   389: aload 16
    //   391: aload 9
    //   393: invokevirtual 275	java/io/ObjectOutputStream:writeObject	(Ljava/lang/Object;)V
    //   396: aload_1
    //   397: ldc_w 277
    //   400: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   403: pop
    //   404: aload_1
    //   405: aload 15
    //   407: invokevirtual 281	java/io/ByteArrayOutputStream:toByteArray	()[B
    //   410: invokestatic 285	org/jivesoftware/smack/util/StringUtils:encodeBase64	([B)Ljava/lang/String;
    //   413: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   416: ldc 245
    //   418: invokevirtual 90	java/lang/StringBuilder:append	(Ljava/lang/String;)Ljava/lang/StringBuilder;
    //   421: pop
    //   422: aload 16
    //   424: ifnull +8 -> 432
    //   427: aload 16
    //   429: invokevirtual 288	java/io/ObjectOutputStream:close	()V
    //   432: aload 15
    //   434: ifnull -234 -> 200
    //   437: aload 15
    //   439: invokevirtual 289	java/io/ByteArrayOutputStream:close	()V
    //   442: goto -242 -> 200
    //   445: astore 27
    //   447: goto -247 -> 200
    //   450: astore 30
    //   452: aload 30
    //   454: astore 18
    //   456: aload 18
    //   458: invokevirtual 292	java/lang/Exception:printStackTrace	()V
    //   461: aload 14
    //   463: ifnull +8 -> 471
    //   466: aload 14
    //   468: invokevirtual 288	java/io/ObjectOutputStream:close	()V
    //   471: aload 13
    //   473: ifnull -273 -> 200
    //   476: aload 13
    //   478: invokevirtual 289	java/io/ByteArrayOutputStream:close	()V
    //   481: goto -281 -> 200
    //   484: astore 22
    //   486: goto -286 -> 200
    //   489: astore 19
    //   491: aload 14
    //   493: ifnull +8 -> 501
    //   496: aload 14
    //   498: invokevirtual 288	java/io/ObjectOutputStream:close	()V
    //   501: aload 13
    //   503: ifnull +8 -> 511
    //   506: aload 13
    //   508: invokevirtual 289	java/io/ByteArrayOutputStream:close	()V
    //   511: aload 19
    //   513: athrow
    //   514: astore 24
    //   516: goto -45 -> 471
    //   519: astore 21
    //   521: goto -20 -> 501
    //   524: astore 20
    //   526: goto -15 -> 511
    //   529: astore 28
    //   531: goto -99 -> 432
    //   534: astore 19
    //   536: aload 15
    //   538: astore 13
    //   540: goto -49 -> 491
    //   543: astore 19
    //   545: aload 16
    //   547: astore 14
    //   549: aload 15
    //   551: astore 13
    //   553: goto -62 -> 491
    //   556: astore 29
    //   558: aload 29
    //   560: astore 18
    //   562: aload 15
    //   564: astore 13
    //   566: goto -110 -> 456
    //   569: astore 17
    //   571: aload 17
    //   573: astore 18
    //   575: aload 16
    //   577: astore 14
    //   579: aload 15
    //   581: astore 13
    //   583: goto -127 -> 456
    //
    // Exception table:
    //   from	to	target	type
    //   2	89	116	finally
    //   94	113	116	finally
    //   121	360	116	finally
    //   427	432	116	finally
    //   437	442	116	finally
    //   466	471	116	finally
    //   476	481	116	finally
    //   496	501	116	finally
    //   506	511	116	finally
    //   511	514	116	finally
    //   437	442	445	java/lang/Exception
    //   369	378	450	java/lang/Exception
    //   476	481	484	java/lang/Exception
    //   369	378	489	finally
    //   456	461	489	finally
    //   466	471	514	java/lang/Exception
    //   496	501	519	java/lang/Exception
    //   506	511	524	java/lang/Exception
    //   427	432	529	java/lang/Exception
    //   378	389	534	finally
    //   389	422	543	finally
    //   378	389	556	java/lang/Exception
    //   389	422	569	java/lang/Exception
  }

  public String getFrom()
  {
    return this.from;
  }

  public String getPacketID()
  {
    String str;
    if ("ID_NOT_AVAILABLE".equals(this.packetID))
      str = null;
    while (true)
    {
      return str;
      if (this.packetID == null)
        this.packetID = nextID();
      str = this.packetID;
    }
  }

  /**
   * @deprecated
   */
  public Object getProperty(String paramString)
  {
    Object localObject2;
    Object localObject3;
    monitorenter;
    try
    {
      Map localMap = this.properties;
      if (localMap == null)
      {
        localObject3 = null;
        monitorexit;
        return localObject3;
      }
      localObject2 = this.properties.get(paramString);
    }
    finally
    {
      monitorexit;
    }
  }

  /**
   * @deprecated
   */
  public Collection<String> getPropertyNames()
  {
    Set localSet1;
    Object localObject2;
    monitorenter;
    try
    {
      if (this.properties == null)
      {
        Set localSet2 = Collections.emptySet();
        localObject2 = localSet2;
        monitorexit;
        return localObject2;
      }
      localSet1 = Collections.unmodifiableSet(new HashSet(this.properties.keySet()));
    }
    finally
    {
      monitorexit;
    }
  }

  public String getTo()
  {
    return this.to;
  }

  public String getXmlns()
  {
    return this.xmlns;
  }

  public int hashCode()
  {
    int i;
    int k;
    int i1;
    int i3;
    int i4;
    int i5;
    if (this.xmlns != null)
    {
      i = this.xmlns.hashCode();
      int j = i * 31;
      if (this.packetID == null)
        break label148;
      k = this.packetID.hashCode();
      int l = 31 * (j + k);
      if (this.to == null)
        break label153;
      i1 = this.to.hashCode();
      int i2 = 31 * (l + i1);
      if (this.from == null)
        break label159;
      i3 = this.from.hashCode();
      i4 = 31 * (31 * (31 * (i2 + i3) + this.packetExtensions.hashCode()) + this.properties.hashCode());
      if (this.error == null)
        break label165;
      i5 = this.error.hashCode();
    }
    while (true)
    {
      while (true)
      {
        while (true)
        {
          while (true)
          {
            while (true)
            {
              return (i4 + i5);
              i = 0;
            }
            label148: k = 0;
          }
          label153: i1 = 0;
        }
        label159: i3 = 0;
      }
      label165: i5 = 0;
    }
  }

  public void removeExtension(PacketExtension paramPacketExtension)
  {
    this.packetExtensions.remove(paramPacketExtension);
  }

  public void setError(XMPPError paramXMPPError)
  {
    this.error = paramXMPPError;
  }

  public void setFrom(String paramString)
  {
    this.from = paramString;
  }

  public void setPacketID(String paramString)
  {
    this.packetID = paramString;
  }

  /**
   * @deprecated
   */
  public void setProperty(String paramString, Object paramObject)
  {
    monitorenter;
    try
    {
      throw new IllegalArgumentException("Value must be serialiazble");
    }
    finally
    {
      monitorexit;
      throw localObject;
      this.properties.put(paramString, paramObject);
      monitorexit;
    }
  }

  public void setTo(String paramString)
  {
    this.to = paramString;
  }

  public abstract String toXML();
}